<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
</head>
<body>
<div class="list-box">
    <div class="nav">
        <ul>
            <li>招聘岗位管理</li>
            <li>/</li>
            <li>岗位列表</li>
        </ul>
    </div>
    <div class="search">
        <form>
            <input type="hidden" id="currPage"/> 职位 : <input type="text" id="title">
            </select> <input type="button" class="btn" value="搜索" id="searchBtn">
        </form>
    </div>
    <div class="toolbar">
        <input type="button" class="btn" value="新增方案" onclick="add()">
        <input type="button" class="btn" value="删除方案" id="deletsBtn">
    </div>
    <div>
        <table id="tt"></table>
    </div>
    <div class="page">
        <ul id="page-bar"></ul>
    </div>
</div>
<script type="text/javascript">
    function loadList(page) {
        page = page == undefined ? 1 : page;
        $.get("/web/recruit", {op: "queryBypage", page: page, title: $("#title").val(), salaryId: 0}, function (data) {
            $("#currPage").val(data.page);
            var table = $("#tt");
            table.empty();
            table.append(`<tr>
                <th><input type="checkbox" onclick="chooseAll()" id="chooseAll"></th>
                <th>岗位编号</th>
                <th>岗位名称</th>
                <th>创建时间</th>
                <th>最后修改时间</th>
                <th>状态</th>
            </tr>`);
            for (var x = 0; x < data.rows.length; x++) {
                var p = data.rows[x];
                table.append(`<tr ${x % 2 != 0 ? 'class="odd"' : ''}>
		                <td><input type="checkbox" ckrecruitid="${p.recruitId}" class="cos"></td>
		                <td>${p.recruitId}</td>
		                <td>${p.recruitName}</td>
		                <td>${p.createTime}</td>
		                <td>${p.modifyTime}</td>
		                <td>${p.status == 1 ? '正常' : '删除'}</td>
		                <td>
		                    <input type="button" class="btn" value="编辑" onclick="exitRecruit(${p.recruitId})">
		                    <input type="button" class="btn" value="删除" onclick="removeRecruit(${p.recruitId})">
		                </td>
		            </tr>`);
            }
            var pageBar = $("#page-bar");
            pageBar.empty();
            pageBar.append("<li onclick='loadList(" + ((page - 1) < 1 ? 1 : (page - 1)) + ")'>&lt;&lt;</li>");
            var start = 1;
            var end = 1;
            if (data.maxPage <= 10) {
                end = data.maxPage;
            } else if (data.maxPage > 10) {
                start = (data.page - 4) > 0 ? (data.page - 4) : 1;
                end = (start + 9) > data.maxPage ? data.maxPage : (start + 9);
            }
            for (var x = start; x <= end; x++) {
                if (x == data.page) {
                    pageBar.append("<li class='page-active' >" + x + "</li>");
                } else {
                    pageBar.append("<li onclick='loadList(" + x + ")'>" + x + "</li>");
                }
            }
            pageBar.append("<li onclick='loadList(" + ((page + 1) > data.maxPage ? data.maxPage : (page + 1)) + ")'>&gt;&gt;</li>");
        });
    }

    function searchBntClick() {
        loadList(1);
    }

    $(function () {
        loadList(1);
        $("#searchBtn").click(searchBntClick);
        $("#deletsBtn").click(function () {
            var cks = $("[ckrecruitid]:checked");
            if (cks == undefined || cks.length == 0) {
                return;
            }
            var param = "op=deletes";
            for (var x = 0; x < cks.length; x++) {
                param += "&recruitId=" + $(cks[x]).attr("ckrecruitid")
            }
            if (confirm("您确定要删除选中的数据吗？")) {
                $.post("/web/recruit", param, function (data) {
                    if (data > '0') {
                        alert("删除成功");
                        loadList($("#currPage").val());
                    } else {
                        alert("删除失败");
                    }
                });
            }
        });
    })

    function chooseAll(){
        $(".cos").prop("checked",$("#chooseAll").prop("checked"));
    }

    function add() {
        $("#content").load("recruit/recruit-add.html");
    }

    function exitRecruit(id) {
        updateId = id;
        $("#content").load("recruit/recruit-update.html");

    }

    function removeRecruit(recruitId) {
        if (confirm("您确定要删除选中的数据吗？")) {
            $.post("/web/recruit", {op: "delete", recruitId: recruitId}, function (data) {
                if (data == 1) {
                    alert("删除成功");
                    loadList($("#currPage").val());
                } else {
                    alert("删除成功");
                }
            });
        }
    }
</script>
</body>
</html>
